﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;
using Component.Worker.RecursiveProcess;

public partial class Controls_News_ctrNewsMenu : System.Web.UI.UserControl
{
    #region Constants
    private int nCurrentLanguage = Support.GetCurrentLanguage();
    private int nDefaultLanguage = Support.GetDefaultLanguage(); 
    #endregion Constants

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.InitData();
            this.BindDataToRptNews1();
        }
    }

    private void InitData()
    {
        lnkNews.Text = MultipleLanguage.LBL_NEWSMENU[nDefaultLanguage - 1].ToUpper();
        lnkNews.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT;
    }
    
    private void BindDataToRptNews1()
    {
        DataTable objTable = new DataTable();
        NewsCategory objNewsCategory = new NewsCategory();
        objTable = objNewsCategory.SearchByParent(0);
        rptNews1.DataSource = objTable;
        rptNews1.DataBind();
    }

    protected void rptNews1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkNewsTitle = (HyperLink)e.Item.FindControl("lnkNewsTitle1");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsCategoryID"));
            switch (nCurrentLanguage)
            {
                case 1:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1")).ToUpper();
                    break;
                case 2:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2")).ToUpper();
                    break;
                case 3:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3")).ToUpper();
                    break;
            }
            lnkNewsTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?" + Config.NEWS_CAT + "=" + nID;

            Repeater rptNews = (Repeater)e.Item.FindControl("rptNews2");
            int nParent = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "Parent"));
            DataTable objTable = new DataTable();
            NewsCategory objNewsCategory = new NewsCategory();
            objTable = objNewsCategory.SearchByParent(nID);

            int nItemCount = objTable.Rows.Count;
            if (nItemCount > 0)
            {
                rptNews.DataSource = objTable;
                rptNews.DataBind();
            }
        }
    }

    protected void rptNews2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkNewsTitle = (HyperLink)e.Item.FindControl("lnkNewsTitle2");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsCategoryID"));
            switch (nCurrentLanguage)
            {
                case 1:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1")).ToUpper();
                    break;
                case 2:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2")).ToUpper();
                    break;
                case 3:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3")).ToUpper();
                    break;
            }
            lnkNewsTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?" + Config.NEWS_CAT + "=" + nID;

            Repeater rptNews = (Repeater)e.Item.FindControl("rptNews3");
            int nParent = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "Parent"));
            DataTable objTable = new DataTable();
            NewsCategory objNewsCategory = new NewsCategory();
            objTable = objNewsCategory.SearchByParent(nID);
            rptNews.DataSource = objTable;
            rptNews.DataBind();
        }
    }

    protected void rptNews3_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkNewsTitle = (HyperLink)e.Item.FindControl("lnkNewsTitle3");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsCategoryID"));
            switch (nCurrentLanguage)
            {
                case 1:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1")).ToUpper();
                    break;
                case 2:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2")).ToUpper();
                    break;
                case 3:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3")).ToUpper();
                    break;
            }
            lnkNewsTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?" + Config.NEWS_CAT + "=" + nID;

            Repeater rptNews = (Repeater)e.Item.FindControl("rptNews3");
            int nParent = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "Parent"));
            DataTable objTable = new DataTable();
            NewsCategory objNewsCategory = new NewsCategory();
            objTable = objNewsCategory.SearchByParent(nID);
            int nItemCount = objTable.Rows.Count;
            if (nItemCount > 0)
            {
                rptNews.DataSource = objTable;
                rptNews.DataBind();
            }
        }
    }

    protected void rptNews4_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkNewsTitle = (HyperLink)e.Item.FindControl("lnkNewsTitle4");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsCategoryID"));
            switch (nCurrentLanguage)
            {
                case 1:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1")).ToUpper();
                    break;
                case 2:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2")).ToUpper();
                    break;
                case 3:
                    lnkNewsTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3")).ToUpper();
                    break;
            }
            lnkNewsTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?" + Config.NEWS_CAT + "=" + nID;
        }
    }

    #region Comment Code
    //private void BindData()
    //{
    //    int nCurrentLanguage = Support.GetCurrentLanguage();
    //    int nDefaultLang = Support.GetDefaultLanguage();
    //    lnkNews.Text = MultipleLanguage.LBL_NEWSMENU[nDefaultLang - 1];

    //    DataTable objTable = new DataTable();
    //    NewsCategory objNewsCategory = new NewsCategory();
    //    objTable = objNewsCategory.Search();
    //    int nCount = objTable.Rows.Count;
    //    FlowCategory flow = new FlowCategory(objTable, VERTICAL_COLUMN_NAME, HOLIZOTAL_COLUMN_NAME);
    //    flow.IDColumnName = "NewsCategoryID";
    //    flow.ParentIDColumName = "[Parent]";
    //    switch (nCurrentLanguage)
    //    {
    //        case 1:
    //            flow.SortColumnName = "Description1";
    //            break;
    //        case 2:
    //            flow.SortColumnName = "Description2";
    //            break;
    //        case 3:
    //            flow.SortColumnName = "Description3";
    //            break;
    //    }

    //    flow.ParentSortDirection = "ASC";
    //    if (flow.Execute(0))
    //    {
    //        mCateData = flow.DestinationData();
    //    }
    //    rptNews1.DataSource = mCateData;
    //    rptNews1.DataBind();
    //}
    //private void textCreateMarginLeft(ref string text, Int16 count)
    //{
    //    if (count > 0)
    //    {
    //        string sMargin = String.Empty;
    //        for (int i = 0; i < count; i++)
    //        {
    //            sMargin += "--";
    //            sMargin += " ";
    //        }
    //        text = sMargin + text;
    //    }
    //}
    //protected void rptNews1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    //{
    //    int nCurrentLang = Support.GetCurrentLanguage();
    //    if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
    //    {
    //        HyperLink lnkNewsTitle = (HyperLink)e.Item.FindControl("lnkNewsTitle");
    //        int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "NewsCategoryID"));

    //        lnkNewsTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_BYCAT + "?nid=" + nID;
    //        string sText = string.Empty;
    //        Int16 iHolz = Convert.ToInt16(DataBinder.Eval(e.Item.DataItem, HOLIZOTAL_COLUMN_NAME));
    //        switch (nCurrentLang)
    //        {
    //            case 1:
    //                sText = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1"));

    //                textCreateMarginLeft(ref sText, iHolz);
    //                lnkNewsTitle.Text = ConvertData.ConvertToString(sText);

    //                break;
    //            case 2:
    //                sText = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2"));

    //                textCreateMarginLeft(ref sText, iHolz);
    //                lnkNewsTitle.Text = ConvertData.ConvertToString(sText);
    //                break;
    //            case 3:
    //                sText = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1"));

    //                textCreateMarginLeft(ref sText, iHolz);
    //                lnkNewsTitle.Text = ConvertData.ConvertToString(sText);
    //                break;
    //        }
    //    }
    //}
    #endregion
}